
//Table A7 final run
log using "$rootpath/log/Table_A7_Results.log", replace
eststo clear
use "$rootpath/processed_data/Estimation_Data.dta", clear
drop if key_estimation_sample==0
sort state_number year
egen min_damage=min(log_damage55), by(state_number year)
egen min_emissions=min(log_emissions4), by(state_number year)
egen max_damages=max(log_damage55), by(state_number year)
egen max_emissions=max(log_emissions4), by(state_number year)
  
sort state_number year
quietly by state_number year:  gen dups = cond(_N==1,0,_n) 
drop if dups>1
drop dups
///This is the robustness check regarding mins and maxes. 
rename avg_old_code_prob policy
regress min_damage policy, cluster(state_number)
estimates store min_dam
regress max_damages policy, cluster(state_number)
estimates store max_dam
regress min_emissions policy, cluster(state_number)
estimates store min_emit
regress max_emissions policy, cluster(state_number)
estimates store max_emit


use "$rootpath/processed_data/Estimation_Data.dta", clear
drop if key_estimation_sample==0
reghdfe  log_emissions4 treatXpost [aweight=new_weight], absorb(facility_id n5#year) vce(cluster facility_id)
estimates store new_weight_emit
reghdfe  log_damage55 treatXpost [aweight=new_weight], absorb(facility_id n5#year) vce(cluster facility_id)
estimates store new_weight_dam

esttab min_dam min_emit max_dam max_emit  new_weight_dam new_weight_emit using "$rootpath/table_graph/TBL_A7.tex",  star( * 0.1 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3))) keep(policy treatXpost) scalars(N F) ar2 replace



log close


